//
// File: xzlanhs.cpp
//
// MATLAB Coder version            : 5.1
// C/C++ source code generated on  : 22-Feb-2021 03:11:30
//

// Include Files
#include "xzlanhs.h"
#include "rt_nonfinite.h"
#include <cmath>

// Function Definitions
//
// Arguments    : const creal_T A[16]
//                int ilo
//                int ihi
// Return Type  : double
//
namespace coder
{
  namespace internal
  {
    namespace reflapack
    {
      double xzlanhs(const creal_T A[16], int ilo, int ihi)
      {
        double colssq;
        double f;
        double ssq;
        int u0;
        f = 0.0;
        if (ilo <= ihi) {
          double scale;
          int nm1;
          scale = 3.3121686421112381E-170;
          ssq = 0.0;
          nm1 = ihi - ilo;
          for (int j = 0; j <= nm1; j++) {
            double absxk;
            double colscale;
            int col;
            colscale = 3.3121686421112381E-170;
            colssq = 0.0;
            col = (ilo + j) - 1;
            u0 = j + 1;
            if (u0 >= nm1) {
              u0 = nm1;
            }

            u0 += ilo;
            for (int row = ilo; row <= u0; row++) {
              double t;
              int re_tmp;
              re_tmp = (row + (col << 2)) - 1;
              absxk = std::abs(A[re_tmp].re);
              if (absxk > colscale) {
                t = colscale / absxk;
                colssq = colssq * t * t + 1.0;
                colscale = absxk;
              } else {
                t = absxk / colscale;
                colssq += t * t;
              }

              absxk = std::abs(A[re_tmp].im);
              if (absxk > colscale) {
                t = colscale / absxk;
                colssq = colssq * t * t + 1.0;
                colscale = absxk;
              } else {
                t = absxk / colscale;
                colssq += t * t;
              }
            }

            if (scale >= colscale) {
              absxk = colscale / scale;
              ssq += absxk * absxk * colssq;
            } else {
              absxk = scale / colscale;
              ssq = colssq + absxk * absxk * ssq;
              scale = colscale;
            }
          }

          f = scale * std::sqrt(ssq);
        }

        return f;
      }
    }
  }
}

//
// File trailer for xzlanhs.cpp
//
// [EOF]
//
